﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using HiauPdm.Bll;
using HiauPdm.Web;

namespace HiauPdm.Web
{
    public partial class WzSfcCx : PageBase
    {
        /// <summary>
        /// 加载
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.MaintainScrollPositionOnPostBack = true;
            if (Page.IsPostBack) { return; }
            if (Request.QueryString["sWhere"] != null)
            {
                TextKsrq.Value = Request.QueryString["sKsrq"];
                BindData(Request.QueryString["sWhere"], Request.QueryString["nPage"]);
            }
            else
            {
                TextKsrq.Value = string.Empty;
            }
            TextWhere.Focus();
        }

        /// <summary>
        /// 绑定刷新数据
        /// </summary>
        private void BindData(string sWhere, string nPage)
        {
            string sJzYf = Request.QueryString["sKsrq"].ToString();
            if (sJzYf != null && sJzYf != string.Empty)
            {
                sJzYf = "JZ" + sJzYf.Replace("-", ".");
            }
            sWhere = (sWhere == null ? string.Empty : sWhere.Trim());
            // 设置页数
            DataSet dsCount = BCkGl.GetWzSfcCxByCxCount(sJzYf, sWhere);
            Pager1.RecordCount = (dsCount == null ? 0 : (int)dsCount.Tables[0].Rows[0][0]);
            Pager1.CurrentPageIndex = (nPage == null ? 1 : int.Parse(nPage));
            // 查询数据
            DataSet ds = BCkGl.GetWzSfcCxByCx(sJzYf, sWhere, Pager1.PageSize, Pager1.CurrentPageIndex);
            if (ds == null || ds.Tables[0].Rows.Count <= 0)
            {
                PanelList1.Visible = true;
                PanelList2.Visible = false;
                return;
            }
            PanelList1.Visible = false;
            PanelList2.Visible = true;
            // 绑定表格
            GridData.DataSource = ds;
            GridData.DataBind();
            GridData.SelectedIndex = -1;
        }
    }
}